<?php
require_once dirname(__FILE__) . '/../common.inc.php';
try {
  $hostname = DB_HOST;
  $username = DB_LOGIN;
  $password = DB_PASS;
  $dbname = DB_NAME;
  $myPdo = new PDO ('mysql:host=' . $hostname, $username, $password);
  $myPdo->exec('USE ' . $dbname);
  $myPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_menu`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `parent_id` int,
           `name` varchar(64),
           `is_default` bool,
           `appear_in_menu` bool,
           `url` char(128),
           `desc` text,
           `keywords` text,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_page`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `menu_id` int,
           `html` text,
           `css` text,
           `js` text
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_plugin`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(64) UNIQUE,
           `folder` varchar(64) UNIQUE
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_plugin_instance`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `menu_id` int,
           `plugin_id` int,
           `width` int,
           `height` int,
           `scrolling` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_profile`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `account` varchar(16) UNIQUE,
           `password` varchar(64),
           `email` varchar(128),
           `title` text,
           `desc` text,
           `keywords` text,
           `mail_host` varchar(64),
           `mail_SMTPAuth` tinyint(1),
           `mail_account` varchar(64),
           `mail_password` varchar(64),
           `mail_from_mail` varchar(64),
           `mail_from_name` varchar(64),
           `theme_id` int
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_theme`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(64) UNIQUE,
           `folder` varchar(64) UNIQUE
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  echo 'Completed Successfully.';
} catch (PDOException $e) {
  echo ERROR_SIGN . $e->getMessage();
}
?>
